package comparisons

import (
	"jvm/nzpJvm/instructions/base"
	"jvm/nzpJvm/runtime_area"
)

// if condition
// 把栈顶的int值弹出，和0进行比较
// 等于0
type IFEQ struct{ base.BranchInstruction }

// 不等于0
type IFNE struct{ base.BranchInstruction }

// 小于0
type IFLT struct{ base.BranchInstruction }

// 小于等于0
type IFLE struct{ base.BranchInstruction }

// 大于0
type IFGT struct{ base.BranchInstruction }

// 大于等于0
type IFGE struct{ base.BranchInstruction }

func (self *IFEQ) Execute(frame *runtime_area.Frame) {
	popInt := frame.OperandStack().PopInt()
	if popInt == 0 {
		base.Branch(frame, self.Offset)
	}
}
func (self *IFNE) Execute(frame *runtime_area.Frame) {
	popInt := frame.OperandStack().PopInt()
	if popInt != 0 {
		base.Branch(frame, self.Offset)
	}
}
func (self *IFLT) Execute(frame *runtime_area.Frame) {
	popInt := frame.OperandStack().PopInt()
	if popInt < 0 {
		base.Branch(frame, self.Offset)
	}
}
func (self *IFLE) Execute(frame *runtime_area.Frame) {
	popInt := frame.OperandStack().PopInt()
	if popInt <= 0 {
		base.Branch(frame, self.Offset)
	}
}
func (self *IFGT) Execute(frame *runtime_area.Frame) {
	popInt := frame.OperandStack().PopInt()
	if popInt > 0 {
		base.Branch(frame, self.Offset)
	}
}
func (self *IFGE) Execute(frame *runtime_area.Frame) {
	popInt := frame.OperandStack().PopInt()
	if popInt >= 0 {
		base.Branch(frame, self.Offset)
	}
}
